<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文章管理 - 会员中心 - 散文吧</title>
    <link href="__ROOT__/shiwen/pc/xin/css/manage.css" rel="stylesheet">
    <style>
        .subject, .content, .submit {
            border-radius: 3px;
        }
        .subject {
            width: 610px;
            padding: 7px;
            border: 1px solid #ccc;
            height: 25px;
            font-size: 24px;
        }
        .content {
            width: 610px;
            padding: 7px;
            border: 1px solid #ccc;
            height: 300px;
            overflow: auto;
        }
        .submit {
            padding: 8px 20px;
            font-weight: bold;
            color: #fff;
            background: #ff8800;
            border: none;
        }
        .frmarea {
            padding: 15px 10px;
        }
        em {
            font-style: normal;
        }
        small {
            color: #999;
            margin-left: 5px;
        }
        .item {
            margin: 5px 0 10px;
        }
        .category {
            border: 1px solid #eee;
            padding: 5px 0;
            width: 624px;
        }
    </style>
    <script src="https://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script src="__ROOT__/shiwen/pc/xin/js/sweetalert.min.js"></script>
    <link rel="stylesheet" href="__ROOT__/shiwen/pc/xin/css/sweetalert.css">
    <script type="text/javascript" src="__ROOT__/shiwen/pc/xin/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__ROOT__/shiwen/pc/xin/ueditor/ueditor.all.js"></script>
</head>
<body>
<div class="wrapper">
    {include file="pc/member/header" /}
    <div id="content">
        <div id="postarticle">
            <h2><span><a href="{:url('member/postblog')}">发日志</a></span>发表文章</h2>
            <div class="frmarea">
                    <input type="hidden" value="{$list.id|default=''}" name="id" id="id"/>
                    <div class="item">
                        <h3><em>标题</em><small>(必填)</small></h3>
                        <input type="text" name="subject" class="subject" value="{$list.title|default=''}"/>
                    </div>
                    <div class="item">
                        <h3><em>摘要</em><small>(选填)</small></h3>
                        <textarea name="summary" class="summary" style="height:100px;width:620px; resize:vertical;">{$list.summary|default=''}</textarea>
                    </div>
                    <div class="item">
                        <h3><em>内容</em></h3>
                        <script id="container" name="content" type="text/plain">{$list.content|raw|default=''}</script>
                    </div>
                    <div class="item">
                        <h3><em>分类栏目</em><small>(请正确选择栏目)</small></h3>
                        <div class="category">
                            <label><input name="tid" type="radio" value="2" {if isset($list.cid) && $list.cid == 2}checked{/if}>散文</label>
                            <label><input name="tid" type="radio" value="3" {if isset($list.cid) && $list.cid == 3}checked{/if}>诗歌</label>
                            <label><input name="tid" type="radio" value="4" {if isset($list.cid) && $list.cid == 4}checked{/if}>杂文</label>
                            <label><input name="tid" type="radio" value="58" {if isset($list.cid) && $list.cid == 58}checked{/if}>小说</label>
                            <label><input name="tid" type="radio" value="5" {if isset($list.cid) && $list.cid == 5}checked{/if}>随笔</label>
                            <label><input name="tid" type="radio" value="82" {if isset($list.cid) && $list.cid == 82}checked{/if}>日记</label>
                        </div>
                    </div>
                    <div class="item">
                        <input type="submit" class="submit" id="btnsubmit" value="提 交"/>
                        &nbsp;&nbsp;&nbsp;
                        <input type="checkbox" name="zhuan" value="1" checked="checked"/>我保证本文是我的原创作品
                    </div>
                    {:token_field()}
            </div>
        </div>
    </div>
    <div id="footer">&copy;2006-{date('Y')} www.okshiwen.cn</div>
</div>
<script type="text/javascript">
    var ue = UE.getEditor('container');

    $(function () {
        $('#btnsubmit').click(function (e) {
            e.preventDefault();

            var subject = $(".subject").val();
            var summary = $(".summary").val();
            var id = $("#id").val();
            var content = ue.getContent();
            var cid = $("input[name='tid']:checked").val();

            if (subject === '') {
                swal("OMG!", "客官，这家伙忘记写标题了!!!", "error");
                return false;
            }

            if(cid === ''){
                swal("OMG!", "客官，这家伙忘记选择分类了!!!", "error");
                return false;
            }

            if (content === '') {
                swal("OMG!", "客官，这家伙忘记填写内容了!!!", "error");
                return false;
            }

            $(this).attr('disabled', true).val('正在提交，请稍后').css({
                'color': '#666',
                'background': '#eee'
            });


            $.ajax({
                url: '/articleSave', // 替换为您的实际接口地址
                type: 'POST',
                dataType: 'json',
                data: {
                    'id': id,
                    'title': subject,
                    'cid': cid,
                    'summary': summary,
                    'content': content
                },
                success: function(res) {
                    if (res.code == 200) {
                        swal("Good!", res.msg, "success");
                        setTimeout(function(){
                            window.location.href = "/member_center.html";
                        },1000);
                    } else {
                        swal("OMG!", res.msg, "error");
                        $('#btnsubmit').attr('disabled', false).val('发 布').css({
                            'color': '#fff',
                            'background': '#ff8800'
                        });
                    }
                },
                error: function(xhr, status, error) {

                }
            });


        });
    });
</script>
</body>
</html>